<template>

    <div class="app-container" v-if="canList">
        <div class="filter-container">
            <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item input"
                      placeholder="活动名称"
                      v-model="listQuery.name">
            </el-input>

            <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item input"
                      placeholder="产品名称"
                      v-model="listQuery.goodsName">
            </el-input>
            <el-select @change='handleFilter' clearable class="filter-item input" style="width: 130px"
                       v-model="listQuery.status"
                       placeholder="状态">
                <el-option v-for="(item,index) in  statusOptions" :key="item" :label="item" :value="index">
                </el-option>
            </el-select>

            <div style="display: inline-block">

                <el-button style="margin-left: 10px;" class="filter-item" type="primary" v-waves icon="el-icon-search"
                           @click="handleFilter">查找
                </el-button>
                <el-button class="filter-item" style="margin-left: 10px;" @click="handleCreate" type="primary"
                           v-if="canSave" icon="el-icon-edit">添加
                </el-button>
                <el-button class="filter-item" type="primary" :loading="downloadLoading" v-waves icon="el-icon-download"
                           @click="handleDownload">导出
                </el-button>
            </div>
        </div>

        <el-table :key='tableKey' :data="list" v-loading="listLoading" border fit highlight-current-row
                  style="width: 100%;">
            <el-table-column align="center" label="序号">
                <template slot-scope="scope">
                    <span>{{scope.row.id}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="活动名称">
                <template slot-scope="scope">
                    <span>{{scope.row.name}}</span>
                </template>
            </el-table-column>
       <!--     <el-table-column align="center" label="产品ID">
                <template slot-scope="scope">
                    <span>{{scope.row.goodsId}}</span>
                </template>
            </el-table-column>-->
         <!--   <el-table-column align="center" label="绑定产品ID">
                <template slot-scope="scope">
                    <span>{{scope.row.bindGoodsId}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="绑定数量">
                <template slot-scope="scope">
                    <span>{{scope.row.bindGoodsQuantity}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="规格id">
                <template slot-scope="scope">
                    <span>{{scope.row.skuId}}</span>
                </template>
            </el-table-column>-->
            <el-table-column align="center" label="不可购买级别">
                <template slot-scope="scope">
                    <span>{{scope.row.level}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="限购数量">
                <template slot-scope="scope">
                    <span>{{scope.row.number}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="是否可以转货">
                <template slot-scope="scope">
                    <span>{{options[scope.row.transfer]}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="是否可以发货">
                <template slot-scope="scope">
                    <span>{{options[scope.row.delivery]}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="必需积分">
                <template slot-scope="scope">
                    <span>{{scope.row.point}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="最多使用换购券">
                <template slot-scope="scope">
                    <span>{{scope.row.maxVoucher}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="最多使用优惠券">
                <template slot-scope="scope">
                    <span>{{scope.row.maxCoupon}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="积分奖励">
                <template slot-scope="scope">
                    <span>{{scope.row.pointReward}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="优惠券奖励">
                <template slot-scope="scope">
                    <span>{{scope.row.couponReward}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="换购券奖励">
                <template slot-scope="scope">
                    <span>{{scope.row.voucherReward}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="代金券奖励">
                <template slot-scope="scope">
                    <span>{{scope.row.cashReward}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="区域奖励省_市_县">
                <template slot-scope="scope">
                    <span>{{scope.row.areaReward}}</span>
                </template>
            </el-table-column><!--
            <el-table-column align="center" label="管理费">
                <template slot-scope="scope">
                    <span>{{scope.row.managerReward}}</span>
                </template>
            </el-table-column>-->
            <el-table-column align="center" label="活动库存">
                <template slot-scope="scope">
                    <span>{{scope.row.stock}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="积分是否立即返利">
                <template slot-scope="scope">
                                                <span>

                         <el-tag :type="tagTypes[scope.row.pointType]">     {{pointTypeOptions[scope.row.pointType]}}</el-tag>

                        </span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="优惠券是否立即返利">
                <template slot-scope="scope">
                                                <span>

                         <el-tag :type="tagTypes[scope.row.couponType]">     {{couponTypeOptions[scope.row.couponType]}}</el-tag>

                        </span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="换购券是否立即返利">
                <template slot-scope="scope">
                                                <span>

                         <el-tag :type="tagTypes[scope.row.voucherType]">     {{voucherTypeOptions[scope.row.voucherType]}}</el-tag>

                        </span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="代金券是否立即返利">
                <template slot-scope="scope">
                                                <span>

                         <el-tag :type="tagTypes[scope.row.cashType]">     {{cashTypeOptions[scope.row.cashType]}}</el-tag>

                        </span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="区域代理奖励是否立即返利">
                <template slot-scope="scope">
                                                <span>

                         <el-tag :type="tagTypes[scope.row.areaType]">     {{areaTypeOptions[scope.row.areaType]}}</el-tag>

                        </span>
                </template>
            </el-table-column>
            <!--<el-table-column align="center" label="管理费是否立即返利">
                <template slot-scope="scope">
                                                <span>

                         <el-tag :type="tagTypes[scope.row.managerType]">     {{managerTypeOptions[scope.row.managerType]}}</el-tag>

                        </span>
                </template>
            </el-table-column>-->
            <el-table-column align="center" label="状态">
                <template slot-scope="scope">
                                                <span>

                         <el-tag :type="tagTypes[scope.row.status]">     {{statusOptions[scope.row.status]}}</el-tag>

                        </span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="开始时间">
                <template slot-scope="scope">
                    <span>{{parseTime(scope.row.start)}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="结束时间">
                <template slot-scope="scope">
                    <span>{{parseTime(scope.row.end)}}</span>
                </template>
            </el-table-column>

            <el-table-column align="center" label="操作" width="230" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button type="primary" v-if="canUpdate" size="mini" @click="handleUpdate(scope)">编辑</el-button>
                    <el-button v-if="canSave" size="mini" type="danger"
                               @click="handleDelete(scope)">删除
                    </el-button>
                </template>
            </el-table-column>

        </el-table>

        <div class="pagination-container" style="margin-top: 20px">
            <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                           :current-page="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.limit"
                           layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>

        <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
    <el-form :rules="rules" ref="dataForm" :model="temp" label-position="left" label-width="120px"
             style='width: 450px; margin-left:50px;'>
        <el-form-item label="活动名称" prop="name">
            <el-input v-model="temp.name"></el-input>
        </el-form-item>
        <el-form-item label="产品" prop="goodsId">
            <!--                    <el-input v-model="temp.goodsId"></el-input>-->
            <el-select v-model="temp.goodsId" filterable placeholder="请选择">
                <el-option
                        v-for="item in goodsList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                </el-option>
            </el-select>
        </el-form-item>

        <el-form-item label="捆绑产品" prop="goodsId">
            <!--                    <el-input v-model="temp.goodsId"></el-input>-->
            <el-select v-model="temp.bindGoodsId" clearable filterable placeholder="请选择">
                <el-option
                        v-for="item in goodsList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="捆绑数量" prop="number">
            <el-input v-model="temp.bindGoodsQuantity"></el-input>
        </el-form-item>


        <el-form-item label="禁购级别" prop="level" size="medium">
            <el-select v-model="temp.levels" clearable multiple placeholder="请选择" width="100px">
                <el-option
                        v-for="item in levelList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.name">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="限购数量" prop="number">
            <el-input v-model="temp.number"></el-input>
        </el-form-item>
        <el-form-item label="是否转货" prop="status">
            <el-select class="filter-item" v-model="temp.transfer" placeholder="是否转货">
                <el-option v-for="(item,index) in  options" :key="item" :label="item"
                           :value="index">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="是否发货" prop="status">
            <el-select class="filter-item" v-model="temp.delivery" placeholder="是否发货">
                <el-option v-for="(item,index) in  options" :key="item" :label="item"
                           :value="index">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="必需积分" prop="point">
            <el-input v-model="temp.point"></el-input>
        </el-form-item>
        <el-form-item label="最多使用换购券" prop="maxVoucher">
            <el-input v-model="temp.maxVoucher"></el-input>
        </el-form-item>
        <el-form-item label="最多使用优惠券" prop="maxCoupon">
            <el-input v-model="temp.maxCoupon"></el-input>
        </el-form-item>
        <el-form-item label="积分奖励" prop="pointReward">
            <el-input v-model="temp.pointReward"></el-input>
        </el-form-item>
        <el-form-item label="优惠券奖励" prop="couponReward">
            <el-input v-model="temp.couponReward"></el-input>
        </el-form-item>
        <el-form-item label="换购券奖励" prop="voucherReward">
            <el-input v-model="temp.voucherReward"></el-input>
        </el-form-item>
        <el-form-item label="代金券奖励" prop="cashReward">
            <el-input v-model="temp.cashReward"></el-input>
        </el-form-item>
        <el-form-item label="区域奖励省_市_县" prop="areaReward">
            <el-input v-model="temp.areaReward"></el-input>
        </el-form-item>
      <!--  <el-form-item label="管理费" prop="managerReward">
            <el-input v-model="temp.managerReward"></el-input>
        </el-form-item>-->
        <el-form-item label="活动库存" prop="stock">
            <el-input v-model="temp.stock"></el-input>
        </el-form-item>
        <el-form-item label="积分是否立即返利" prop="status">
            <el-select class="filter-item" v-model="temp.pointType" placeholder="积分是否立即返利">
                <el-option v-for="(item,index) in  pointTypeOptions" :key="item" :label="item"
                           :value="index">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="优惠劵是否立即返利" prop="status">
            <el-select class="filter-item" v-model="temp.couponType" placeholder="优惠劵是否立即返利">
                <el-option v-for="(item,index) in  couponTypeOptions" :key="item" :label="item"
                           :value="index">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="换购券是否立即返利" prop="status">
            <el-select class="filter-item" v-model="temp.voucherType" placeholder="换购券是否立即返利">
                <el-option v-for="(item,index) in  voucherTypeOptions" :key="item" :label="item"
                           :value="index">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="代金券是否立即返利" prop="status">
            <el-select class="filter-item" v-model="temp.cashType" placeholder="代金券是否立即返利">
                <el-option v-for="(item,index) in  cashTypeOptions" :key="item" :label="item"
                           :value="index">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="区域代理奖励是否立即返利" prop="status">
            <el-select class="filter-item" v-model="temp.areaType" placeholder="区域代理奖励是否立即返利">
                <el-option v-for="(item,index) in  areaTypeOptions" :key="item" :label="item"
                           :value="index">
                </el-option>
            </el-select>
        </el-form-item>
        <!--<el-form-item label="管理费是否立即返利" prop="status">
            <el-select class="filter-item" v-model="temp.managerType" placeholder="管理费是否立即返利">
                <el-option v-for="(item,index) in  managerTypeOptions" :key="item" :label="item"
                           :value="index">
                </el-option>
            </el-select>
        </el-form-item>-->
        <el-form-item label="状态" prop="status">
            <el-select class="filter-item" v-model="temp.status" placeholder="状态">
                <el-option v-for="(item,index) in  statusOptions" :key="item" :label="item"
                           :value="index">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="开始时间" prop="date">
            <el-date-picker v-model="temp.start" type="datetime"
                            value-format="yyyy-MM-dd HH:mm:ss" placeholder="开始时间">
            </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="date">
            <el-date-picker v-model="temp.end" type="datetime"
                            value-format="yyyy-MM-dd HH:mm:ss" placeholder="结束时间">
            </el-date-picker>
        </el-form-item>

    </el-form>
    <div slot="footer" class="dialog-footer">
        <el-button @click="closeDialogForm">取消</el-button>
        <el-button v-if="dialogStatus=='create'" type="primary" @click="createData">确认</el-button>
        <el-button v-else type="primary" @click="updateData">确认</el-button>
    </div>
</el-dialog>
    </div>
</template>
<style type="stylus">
    .filter-container {
        /*padding-bottom: 20px;*/
    }

    .filter-item {
        margin-bottom: 10px;
    }

    .filter-item.input {
        /*line-height: 60px*/
        margin-right: 10px;
    }
</style>

<script>
    import {list, save, update, remove,info} from '@/api/mall_act'
    import waves from '@/directive/waves' // 水波纹指令
    import {parseTime} from '@/utils'


    import {mapGetters} from 'vuex'
    import {hasAuth} from '@/utils/auth'

    export default {
        name: 'test',
        directives: {
            waves
        },
        data() {
            return {
                topSumList: [],
                levelList: [],
                goodsList: [],
                tableKey: 0,
                list: null,
                total: null,
                listLoading: true,
                start: null
                ,
                end: null
                ,
                listQuery: {
                    page: 1,
                    limit: 20,
                    order: 'id desc'
                    ,
                    goodsName:null,
                    name: null
                    ,
                    goodsId: null
                    ,
                    bindGoodsId: null
                    ,
                    bindGoodsQuantity: null
                    ,
                    skuId: null
                    ,
                    level: null
                    ,
                    number: null
                    ,
                    transfer: null
                    ,
                    delivery: null
                    ,
                    point: null
                    ,
                    maxVoucher: null
                    ,
                    maxCoupon: null
                    ,
                    pointReward: null
                    ,
                    couponReward: null
                    ,
                    voucherReward: null
                    ,
                    cashReward: null
                    ,
                    areaReward: null
                    ,
                    managerReward: null
                    ,
                    stock: null
                    ,
                    start: null,
                    starts: null
                    ,
                    end: null,
                    ends: null
                    ,
                    pointType: null
                    ,
                    couponType: null
                    ,
                    voucherType: null
                    ,
                    cashType: null
                    ,
                    areaType: null
                    ,
                    managerType: null
                    ,
                    status: null
                },

                options:["否","是"],
                pointTypeOptions: ["否", "是"],
                couponTypeOptions: ["否", "是"],
                voucherTypeOptions: ["否", "是"],
                cashTypeOptions: ["否", "是"],
                areaTypeOptions: ["否", "是"],
                managerTypeOptions: ["否", "是"],
                statusOptions: ["打开", "关闭"],
                tagTypes: ['info', '', 'warning', 'danger', 'warning'],
                temp:
                    {
                        id: null,
                        name: null,
                        goodsId: null,
                        bindGoodsId: null,
                        bindGoodsQuantity: null,
                        skuId: null,
                        start: null,
                        end: null,
                        level: null,
                        number: null,
                        transfer: null,
                        delivery: null,
                        point: null,
                        maxVoucher: null,
                        maxCoupon: null,
                        pointReward: null,
                        pointType: null,
                        couponReward: null,
                        couponType: null,
                        voucherReward: null,
                        voucherType: null,
                        cashReward: null,
                        cashType: null,
                        areaReward: null,
                        areaType: null,
                        managerReward: null,
                        managerType: null,
                        stock: null,
                        status: null
                    }
                ,
                dialogFormVisible: false,
                dialogSumFormVisible: false,
                dialogStatus:
                    '',
                textMap:
                    {
                        update: '修改',
                        create:
                            '新增'
                    }
                ,
                rules:
                    {
                        name: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        goodsId: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        bindGoodsId: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        bindGoodsQuantity: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        skuId: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        start: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        end: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        level: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        number: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        transfer: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        delivery: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        point: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        maxVoucher: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        maxCoupon: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        pointReward: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        pointType: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'blur'
                            }
                        ]
                        ,
                        couponReward: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        couponType: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'blur'
                            }
                        ]
                        ,
                        voucherReward: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        voucherType: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'blur'
                            }
                        ]
                        ,
                        cashReward: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        cashType: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'blur'
                            }
                        ]
                        ,
                        areaReward: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        areaType: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'blur'
                            }
                        ]
                        ,
                        managerReward: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        managerType: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'blur'
                            }
                        ]
                        ,
                        stock: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        status: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'blur'
                            }
                        ]
                    }
                ,
                downloadLoading: false,
                qData:
                    {
                        token: '',
                        key:
                            ''
                    }
            }
        },
        created() {
            this.getList()
        },
        computed: {
            ...mapGetters([
                'perms'
            ]),
            canSave() {
                return hasAuth(this.perms, 'mall:act:save')
            },
            canDelete() {
                return hasAuth(this.perms, 'mall:act:delete')
            },
            canUpdate() {
                return hasAuth(this.perms, 'mall:act:update')
            },
            canList() {
                return hasAuth(this.perms, 'mall:act:list')
            }
        },
        methods: {
            sumTop(actId) {
                sumTop(actId).then(res => {
                    this.topSumList = res.data
                    this.dialogSumFormVisible = true
                })
            },
            parseTime(time) {
                return parseTime(time)
            },
            getList() {
                this.listLoading = true
                list(this.listQuery).then(response => {
                    this.list = response.data.list
                    this.goodsList = response.extra.goodsList
                    this.levelList = response.extra.levelList
                    this.total = response.data.total
                    this.listLoading = false
                })
            },
            handleFilter() {
                this.listQuery.page = 1
                this.getList()
            },
            handleSizeChange(val) {
                this.listQuery.limit = val
                this.getList()
            },
            handleCurrentChange(val) {
                this.listQuery.page = val
                this.getList()
            },
            handleModifyStatus(row, status) {
                this.$message({
                    message: '操作成功',
                    type: 'success'
                })
                row.status = status
            },
            beforeFormShow(row) {
                this.resetTemp(row) // 更新数据


            },
            afterFormShow(row) {

            },
            beforeFormCommit() {
                this.getLevel()
            },
            resetTemp(row) {

                this.temp = {}
                if (row) {
                    if (this.temp.transfer == null){
                        this.temp.transfer = 0
                    }
                    if (this.temp.delivery == null){
                        this.temp.delivery = 0
                    }
                    this.temp = Object.assign({}, row) // copy obj
                    this.getLevels();
                }

            },
            handleCreate() {
                this.beforeFormShow()
                this.resetTemp()
                this.dialogStatus = 'create'
                this.dialogFormVisible = true
                this.$nextTick(() => {
                    this.afterFormShow()
                    this.$refs['dataForm'].clearValidate()
                })
            },
            handleDelete(scope) {
                this.index = scope.$index
                // this.beforeFormShow(scope.row)
                // this.temp = Object.assign({}, row) // copy obj
                this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    // this.$message({
                    //   type: 'success',
                    //   message: '删除成功!'
                    // })
                    this.deleteData()
                }).catch(() => {
                    this.$message({
                        type: 'error',
                        message: '删除失败'
                    })
                })
            },
            createData() {
                this.$refs['dataForm'].validate((valid) => {
                        if (valid) {
                            this.beforeFormCommit()
                            save(this.temp).then(res => {
                                this.temp = res.data
                                this.list.unshift(this.temp)
                                this.closeDialogForm()
                                this.$notify({
                                    title: '成功',
                                    message: '创建成功',
                                    type: 'success',
                                    duration: 2000
                                })
                            })
                        }
                    }
                )
            },
            deleteData() {
                // const ids = [this.temp.id]
                const ids = [this.list[this.index].id]
                remove({ids: ids}).then(res => {
                    // 从当前队列中移除
                    this.list.splice(this.index, 1)
                    this.$notify({
                        title: '成功',
                        message: '删除成功',
                        type: 'success',
                        duration: 2000
                    })
                })
            },
            getLevels() {

                if (this.temp.level) {
                    // this.temp.levels = this.temp.level.split("_")
                    this.$set(this.temp, "levels", this.temp.level.split("_"))
                }
            },
            getLevel() {
                if (this.temp.levels) {
                    let str = '';
                    this.temp.levels.forEach(p => {
                        str += p + '_'
                    })
                    this.temp.level = str.substr(0, str.length - 1)
                }
            },
            handleUpdate(scope) {
                this.index = scope.$index
                info(scope.row.id).then(res => {
                    this.beforeFormShow(res.data)
                    this.dialogStatus = 'update'
                    this.dialogFormVisible = true
                    this.$nextTick(() => {
                        this.$refs['dataForm'].clearValidate()
                    })
                })

            },
            updateData() {
                this.$refs['dataForm'].validate((valid) => {
                        if (valid) {
                            this.beforeFormCommit()
                            console.log(this.temp)
                            update(this.temp).then(() => {
                                this.list.splice(this.index, 1, this.temp)
                                this.closeDialogForm()
                                this.$notify({
                                    title: '成功',
                                    message: '更新成功',
                                    type: 'success',
                                    duration: 2000
                                })
                            })
                        }
                    }
                )
            },
            closeDialogForm() {
                this.dialogFormVisible = false
            },
            handleDownload() {
                this.downloadLoading = true
                import('@/vendor/Export2Excel').then(excel => {
                    const tHeader = [
                        '序号'
                        ,
                        '活动名称'
                        ,
                        '产品ID'
                        ,
                        '绑定产品ID'
                        ,
                        '绑定数量'
                        ,
                        '不可购买级别'
                        ,
                        '限购数量'
                        ,
                        '优惠卷奖励'
                        ,
                        '现金卷奖励'
                        ,
                        '区域奖励省_市_县'
                        ,
                        '管理费'
                        ,
                        '活动库存'
                        ,
                        '是否立即返利'
                        ,
                        '是否立即返利'
                        ,
                        '是否立即返利'
                        ,
                        '是否立即返利'
                        ,
                        '状态'
                        ,
                        '开始时间'
                        ,
                        '结束时间'
                    ]
                    const filterVal = ['id'
                        , 'name'
                        , 'goodsId'
                        , 'bindGoodsId'
                        , 'bindGoodsQuantity'
                        , 'level'
                        , 'number'
                        , 'couponReward'
                        , 'cashReward'
                        , 'areaReward'
                        , 'managerReward'
                        , 'stock'
                        ,
                        'couponType'
                        ,
                        'cashType'
                        ,
                        'areaType'
                        ,
                        'managerType'
                        ,
                        'status'
                        ,
                        'start'
                        ,
                        'end'
                    ]
                    const data = this.formatJson(filterVal, this.list)
                    excel.export_json_to_excel({
                        header: tHeader,
                        data,
                        filename: 'table-list'
                    })
                    this.downloadLoading = false
                })
            },
            formatJson(filterVal, jsonData) {
                return jsonData.map(v => filterVal.map(j => {
                        return v[j]
                    }
                ))
            },
        }
    }
</script>
